package com.yami.shop.api.controller;

import cn.hutool.core.date.DateUtil;
import com.google.common.collect.Maps;
import com.yami.shop.bean.app.param.SendSmsParam;
import com.yami.shop.bean.dto.UserVipLevelDto;
import com.yami.shop.bean.enums.SmsType;
import com.yami.shop.bean.model.User;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.otherservice.OneLevelDistributionService;
import com.yami.shop.otherservice.ThreeLevelDistributionService;
import com.yami.shop.otherservice.UserLevelUpgradeService;
import com.yami.shop.otherservice.UserVipLevelUpgradeService;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.SmsLogService;
import com.yami.shop.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private ThreeLevelDistributionService threeLevelDistributionService;
    @Autowired
    private UserService userService;

    @Autowired
    private UserVipLevelUpgradeService userVipLevelUpgradeService;

    @Autowired
    private UserLevelUpgradeService userLevelUpgradeService;

    @Autowired
    private OneLevelDistributionService oneLevelDistributionService;

    /**
     * 测试收货时发送三级奖励
     * @param orderId
     * @return
     */
    @GetMapping("/test1")
    public ServerResponseEntity<Void> test1(String orderId) {
        threeLevelDistributionService.grantReward(orderId);
        return ServerResponseEntity.success();
    }

    @GetMapping("/test2")
    public ServerResponseEntity<List<UserVipLevelDto>> test2(String uid) {
        List<UserVipLevelDto> higherLevelVip = userService.getHigherLevelVip(uid);
        return ServerResponseEntity.success(higherLevelVip);
    }

    @GetMapping("/test3")
    public ServerResponseEntity<List<UserVipLevelDto>> test3(String uid) {
        userVipLevelUpgradeService.autoUpgrade(uid);
        return ServerResponseEntity.success();
    }

    @GetMapping("/test4")
    public ServerResponseEntity<List<UserVipLevelDto>> test4(String uid) {
        threeLevelDistributionService.grantReward2Yuan(uid,"");
        return ServerResponseEntity.success();
    }

    @GetMapping("/test5")
    public ServerResponseEntity<List<User>> test5(String uid) {
        List<User> lowerLevel = userService.getLowerLevel(uid, new ArrayList<>());
        return ServerResponseEntity.success(lowerLevel);
    }

    @GetMapping("/test6")
    public ServerResponseEntity<List<User>> test6(String uid) {
        userVipLevelUpgradeService.autoUpgradeAllHigherLevel(uid);
        return ServerResponseEntity.success();
    }

    @GetMapping("/test7")
    public ServerResponseEntity<Map<String, Object>> test7(String uid) {
        Map<String, Object> map = userLevelUpgradeService.expireDateRemind(uid);
        return ServerResponseEntity.success(map);
    }

    @GetMapping("/test8")
    public ServerResponseEntity<Map<String, Object>> test8(String uid) {
        userLevelUpgradeService.deactivateExpireMember();
        return ServerResponseEntity.success();
    }

    @GetMapping("/test9")
    public ServerResponseEntity<List<User>> test9(String uid) {
        List<User> sevenDayExpireMember = userLevelUpgradeService.getSevenDayExpireMember();
        return ServerResponseEntity.success(sevenDayExpireMember);
    }

    @GetMapping("/test10")
    public ServerResponseEntity<Long> test10(String teamLeaderId,String date) {
        Long teamPerformance = oneLevelDistributionService.getTeamPerformance(teamLeaderId, DateUtil.parse(date, "yyyy-MM-dd HH:mm:ss"));
        return ServerResponseEntity.success(teamPerformance);
    }

    @GetMapping("/test11")
    public ServerResponseEntity<Long> test11(String date) {
        oneLevelDistributionService.grantTeamLeaderReward(DateUtil.parse(date));
        return ServerResponseEntity.success();
    }

    @GetMapping("/test12")
    public ServerResponseEntity<Long> test12() {
        oneLevelDistributionService.saveDayBonusUserToRedis();
        return ServerResponseEntity.success();
    }

    @GetMapping("/test13")
    public ServerResponseEntity<List<User>> test13(String date) {
        List<User> dayBonusUserFromRedis = oneLevelDistributionService.getDayBonusUserFromRedis(date);
        return ServerResponseEntity.success(dayBonusUserFromRedis);
    }

    @GetMapping("/test14")
    public ServerResponseEntity<List<User>> test14(String date) {
        oneLevelDistributionService.grantDayBonus(date);
        return ServerResponseEntity.success();
    }

    @GetMapping("/test15")
    public ServerResponseEntity<List<User>> test15(String uid,String orderNumber) {
        oneLevelDistributionService.referenceOrderAndRepeatOrderReward(uid,orderNumber);
        return ServerResponseEntity.success();
    }
}
